import QN from './qn_sdk.js'

console.log('qn_sdk', QN)


let measurementData = {
  "measurement": [{ "type": 1, "value": 65.35 }, { "type": 2, "value": 22.60 }, { "type": 3, "value": 20.80 }, { "type": 4, "value": 18.80 }, { "type": 5, "value": 5 }, { "type": 6, "value": 57.20 }, { "type": 7, "value": 51.10 }, { "type": 8, "value": 2.59 }, { "type": 9, "value": 1487.00 }, { "type": 10, "value": 4 }, { "type": 11, "value": 18.08 }, { "type": 12, "value": 51.74 }, { "type": 13, "value": 49.17 }, { "type": 14, "value": 29 }, { "type": 15, "value": 94.40 }, { "type": 16, "value": 83 }, { "type": 17, "value": 3.40 }]
}

let newData = QN.formatItemData(measurementData.measurement)
//必需,添加用户的生日、性别、身高
newData.birthday = '1990-01-01'
newData.gender = 1
newData.height = 170

let resultData = QN.reportData(newData)

console.log('resultData', resultData)



let fetchParams = QN.fetchParams({
  appid: 'appid',//更换为正确的参数
  secret: 'appid',//更换为正确的参数
  height: 170,//用户身高
  age: 26, //用户年龄
  gender: 1,//用户性别(1男0女)
  encryptStr: 'b49886d28e8926af9a9b6e87'//扫码得到的加密字符
})

//wx.request 仅做例子，网页中请自行修改为 ajax 的方式
wx.request({
  method: 'post',
  url: 'http://api.yolanda.hk/open_api/calcs/qn.json',
  data: fetchParams,
  success: res => {
    console.log('请求结果1', res)
    //得到resultData进行字段转换
    let data = QN.fieldTransform(res.data.resultData)
    //必需,添加用户的生日
    data.birthday = '1990-01-01'
    data.gender = 1
    data.height = 170
    //通过reportData得到指标数组reportItemList
    let result = QN.reportData(data)
    console.log('result', result)
  }
})